﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace Clinic.Personnel
{
    public partial class Doctors : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Profile.GetProfile("test");
            dvDoctors.DefaultMode = DetailsViewMode.ReadOnly;
            if (!Page.IsPostBack)
            {
                mvDoctors.SetActiveView(vDoctorsList);
            }
        }
        protected void lbtnSelectDoctor_Click(object sender, EventArgs e)
        {
            mvDoctors.SetActiveView(vDoctorInfo);
            dvDoctors.DataBind();
        }
        protected void lbtnAddNewDoctor_Click(object sender, EventArgs e)
        {
            mvDoctors.SetActiveView(vDoctorInfo);
            dvDoctors.ChangeMode(DetailsViewMode.Insert);
        }

        protected void lbtnCancelInsert_Click(object sender, EventArgs e)
        {
            mvDoctors.SetActiveView(vDoctorsList);
            dvDoctors.ChangeMode(DetailsViewMode.ReadOnly);
        }

        protected void lbtnAddDoctor_Click(object sender, EventArgs e)
        {
            dvDoctors.InsertItem(true);
            gvDoctorList.DataBind();
            mvDoctors.SetActiveView(vDoctorsList);
        }

        protected void lbtnDeleteDoctor_Click(object sender, EventArgs e)
        {
            dvDoctors.DeleteItem();
            gvDoctorList.DataBind();
            mvDoctors.SetActiveView(vDoctorsList);
        }

        protected void lbtnBackToList_Click(object sender, EventArgs e)
        {
            gvDoctorList.DataBind();
            mvDoctors.SetActiveView(vDoctorsList);
            dvDoctors.ChangeMode(DetailsViewMode.ReadOnly);
        }
        protected void dvDoctors_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            //a hack for detailsview control
            //when a "null" guid is used as a key in the keys collection it is stored as dbnull type
            //and this leads to conversion problems
            if (e.Keys["UserId"] is DBNull)
            {
                e.Keys.Remove("UserId");
                object userId = null;
                e.Keys.Add("UserId", userId);
            }
            
        }
        protected void dvDoctors_ItemDeleting(object sender, DetailsViewDeleteEventArgs e)
        {
            //user id is not needed when deleting
            e.Keys.Remove("UserId");
        }
}
}